package com.ymatou.iapi.login.testcase;

import java.util.Date;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.login.parameter.ThirdpartyLoginBean;
import com.ymatou.iapi.login.parameter.WeiXinUserRequestDtoBean;
import com.ymatou.iapi.login.parameter.ThirdpartyLoginBean;
import com.ymatou.iapi.login.service.ThirdpartyLoginCall;
import com.ymatou.iapi.login.service.WeiXinUserRequestDtoCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymatou.iapi.userservice.parameter.enums.AppSourceEnum;
import com.ymatou.iapi.userservice.parameter.enums.TerminalSourceEnum;
import com.ymatou.iapi.userservice.parameter.enums.ThirdPartyTypeEnum;
import com.ymatou.iapi.userservice.parameter.req.BindThirdPartyUserReq;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.parameter.req.UnBindThirdPartyUserReq;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.ThirdpartyUserbind;
import com.ymttest.database.model.ThirdpartyUserbindHistory;
import com.ymttest.database.model.Userinfoex;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.AppTypeChannel;
import com.ymttest.utils.constant.ECode;
/**
*第三方联合登录
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_ThirdpartyLogin{
	private static ThirdpartyLoginBean loginBean;
	private static ThirdpartyLoginCall loginCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("第三方联合登录");
	}

	@Before
	public void caseUp() {
		loginBean=new ThirdpartyLoginBean();
		loginCall=new ThirdpartyLoginCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(loginCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	private void verifyDBBind(Integer uid, ThirdpartyLoginBean cq) {
		//TODO 需要检查字段
		JUserWapper ju=new JUserWapper();
		
		Logger.comment("验证thirdparty_userbind");
		ThirdpartyUserbind thirdinfo = ju.selectthirdpartyuserbind(uid).get(0);
		Logger.verifyEquals(cq.getThirdPartyId(), thirdinfo.getThirdPartyId(), "验证ThirdPartyId");
		Logger.verifyEquals(ThirdPartyTypeEnum.QQ.getCode(), thirdinfo.getThirdPartyType(), "验证ThirdPartyType");
	}
	private void verifyDB(Integer uid, ThirdpartyLoginBean cq) {
		//TODO 需要检查字段
		JUserWapper ju=new JUserWapper();
		if(cq.getDid().equals("testChannelSource")){
			Userinfoex ex = ju.selectUserinfoexByUid(uid).get(0);
			Logger.verifyEquals(cq.getThirdPartyType().getCode(), ex.getChannelSource(), "验证ChannelSource");
		}
		
		Logger.comment("验证thirdparty_userbind");
		ThirdpartyUserbind thirdinfo = ju.selectthirdpartyuserbind(uid).get(0);
		Logger.verifyEquals(cq.getThirdPartyId(), thirdinfo.getThirdPartyId(), "验证ThirdPartyId");
		Logger.verifyEquals(cq.getThirdPartyType().getCode(), thirdinfo.getThirdPartyType(), "验证ThirdPartyType");
		
		Logger.comment("验证thirdparty_userbind_history");
		ThirdpartyUserbindHistory thirdinfohist = ju.selectthirdpartyuserbindhistory(uid).get(0);
		Logger.verifyEquals(true, thirdinfohist.getBinding(), "验证binding状态");
		Logger.verifyEquals(cq.getAppSource().getCode(), thirdinfohist.getAppSource(), "验证AppSource");
		Logger.verifyEquals(cq.getClientIp(), thirdinfohist.getClientIp(), "验证ClientIp");
		Logger.verifyEquals(cq.getDeviceId(), thirdinfohist.getDeviceId(), "验证DeviceId");
		Logger.verifyEquals(cq.getMail(), thirdinfohist.getEmail(), "验证Email");
		Logger.verifyEquals(cq.getDid(), thirdinfohist.getEquimentid(), "验证Equimentid");
		Logger.verifyEquals(cq.getMobile(), thirdinfohist.getLoginMobile(), "验证LoginMobile");
		Logger.verifyEquals(cq.getTerminalSource().getCode(), thirdinfohist.getTerminalSource(), "验证TerminalSource");
		Logger.verifyEquals(cq.getThirdPartyType().getCode(), thirdinfohist.getThirdPartyType(), "验证ThirdParty");
		Logger.verifyEquals(cq.getThirdPartyId(), thirdinfohist.getThirdPartyId(), "验证ThirdPartyId");
		if(cq.getThirdPartyUserName()==null){
			Logger.verifyIsContains(".qq", thirdinfohist.getThirdPartyUserName(), "验证ThirdPartyUserName");
		}else{
			Logger.verifyEquals(cq.getThirdPartyUserName()+"", thirdinfohist.getThirdPartyUserName(), "验证ThirdPartyUserName");
		}
	}
	
//	1.第三方联合登入时传入新的第三方账号且传入手机号为新用户,注册第三方成功

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ThirdpartyLogin_001() {
		Logger.start(true,"QQ账号第一次授权,创建用户成功");
		try {
			String aliUserId = "ali_"+TestDataManager.getRandomNum(10);
			String phone = TestDataManager.getPhoneNum();
			
			Logger.comment("绑定手机号，注册QQ账号");
			loginBean=JUserCallService.initLoginBean();
			loginBean.setMobile(phone);
			loginBean.setDid("testChannelSource");
			loginCall.setData(loginBean);
			loginCall.callService();	
			
			Logger.verifyEquals(ECode.SUCCESS, loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", loginCall.getString("Success"), "验证是否成功");
			Integer uid=loginCall.getJsonObject().get("Result").getAsJsonObject().get("UserId").getAsInt();
		
			Logger.comment("和数据库进行数据校验");
			verifyDB(uid,loginBean);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
//	2.第三方联合登入时传入新的第三方账号且传入手机号为码头已存在用户,这个用户没有绑定过对应第三方账号,绑定成功
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ThirdpartyLogin_002() {
		Logger.start(true,"第三方联合登入时传入新的第三方账号且传入手机号为码头已存在用户,这个用户没有绑定过对应第三方账号,绑定成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			String aliUserId = "ali_"+TestDataManager.getRandomNum(10);
			
			loginBean=JUserCallService.initLoginBean();
			loginBean.setMobile(cur.getMobile());
			
			loginCall.setData(loginBean);
			loginCall.callService();	
			
			Logger.verifyEquals("login", loginCall.getResult().get("Remark"), "验证Remark信息");
			Logger.verifyEquals(ECode.SUCCESS, loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", loginCall.getString("Success"), "验证是否成功");
			
			verifyDBBind(uid,loginBean);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
//	3.第三方联合登入时传入新的第三方账号且传入手机号为码头已存在用户,这个用户绑定过对应第三方账号,失败
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ThirdpartyLogin_003() {
		Logger.start(true,"第三方联合登入时传入新的第三方账号且传入手机号为码头已存在用户,这个用户绑定过对应第三方账号,失败");
		try {
			CreateUserReq cur = new CreateUserReq();
			
			cur = JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			
			String aliUserId = "ali_"+TestDataManager.getRandomNum(10);
			BindThirdPartyUserReq third=JUserCallService.initBindThirdUserReq(uid);
			third.setThirdPartyType(ThirdPartyTypeEnum.QQ);
			
			JUserCallService.bindThirdPartyUserCall(third);
			
			loginBean=JUserCallService.initLoginBean();
			loginBean.setMobile(cur.getMobile());

			loginCall.setData(loginBean);
			loginCall.callService();	
			
			Logger.verifyIsContains("该手机号码已经绑定过QQ了，换一个试试吧~", loginCall.getString("LastErrorMessage"), "验证返回的LastErrorMessage信息");
			Logger.verifyEquals("400" ,loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("false", loginCall.getString("Success"), "验证是否成功");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

//	4.三方联合登入时传入已存在未解绑第三方账号,码头用户手机为空,来源为WAP,需要绑定手机
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ThirdpartyLogin_004() {
		Logger.start(true,"三方联合登入时传入已存在未解绑第三方账号,码头用户手机为空,来源为WAP,需要绑定手机");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setMobile(null);
			int uid = JUserCallService.createUserCall(cur);
			String aliUserId = "QQ_"+TestDataManager.getRandomNum(10);
			BindThirdPartyUserReq third=JUserCallService.initBindThirdUserReq(uid);
			third.setThirdPartyType(ThirdPartyTypeEnum.Alipay);
			JUserCallService.bindThirdPartyUserCall(third);
			
			loginBean=JUserCallService.initLoginBean();
			
			loginBean.setThirdPartyId(aliUserId);
			loginBean.setAppSource(AppSourceEnum.Wap);

			loginCall.setData(loginBean);
			loginCall.callService();	
			
			Logger.verifyIsContains("为了您的账户安全，请绑定你的手机号码", loginCall.getString("LastErrorMessage"), "验证返回的LastErrorMessage信息");
			Logger.verifyEquals("400" ,loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("false", loginCall.getString("Success"), "验证是否成功");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
//	5.三方联合登入时传入已存在未解绑第三方账号,码头用户手机为空,来源为非WAP(app),登入成功
	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	//都需要手机号
	public void Tc_ThirdpartyLogin_005() {
		Logger.start(true,"三方联合登入时传入已存在未解绑第三方账号,码头用户手机为空,来源为非WAP(app),登入成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
//			cur.setMobile(null);
			int uid = JUserCallService.createUserCall(cur);
			String aliUserId = "ali_"+TestDataManager.getRandomNum(10);
			BindThirdPartyUserReq third=JUserCallService.initBindThirdUserReq(uid);
			third.setThirdPartyId(aliUserId);
			third.setThirdPartyType(ThirdPartyTypeEnum.Alipay);
			JUserCallService.bindThirdPartyUserCall(third);
			
			loginBean=JUserCallService.initLoginBean();
			
			loginBean.setThirdPartyId(aliUserId);

			loginCall.setData(loginBean);
			loginCall.callService();			
			
			Logger.verifyIsContains("登录成功", loginCall.getString("SuccessMessage"), "验证返回的SuccessMessage信息");
			Logger.verifyEquals("200" ,loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", loginCall.getString("Success"), "验证是否成功");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
//	6.三方联合登入时传入已存在未解绑第三方账号,码头用户手机和传入手机号一致,登入成功
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ThirdpartyLogin_006() {
		Logger.start(true,"三方联合登入时传入已存在未解绑第三方账号,码头用户手机和传入手机号一致,登入成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			String aliUserId = "ali_"+TestDataManager.getRandomNum(10);
			BindThirdPartyUserReq third=JUserCallService.initBindThirdUserReq(uid);
			third.setThirdPartyId(aliUserId);
			third.setThirdPartyType(ThirdPartyTypeEnum.Alipay);
			JUserCallService.bindThirdPartyUserCall(third);
			
			loginBean=JUserCallService.initLoginBean();
			
			loginBean.setMobile(cur.getMobile());
			loginBean.setThirdPartyId(aliUserId);

			loginCall.setData(loginBean);
			loginCall.callService();			
			
			Logger.verifyIsContains("登录成功", loginCall.getString("SuccessMessage"), "验证返回的SuccessMessage信息");
			Logger.verifyEquals("200" ,loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", loginCall.getString("Success"), "验证是否成功");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
//	7.三方联合登入时传入已存在未解绑第三方账号,码头用户手机为空,第三方传入新手机号,绑定登入成功
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ThirdpartyLogin_007() {
		Logger.start(true,"三方联合登入时传入已存在未解绑第三方账号,码头用户手机为空,第三方传入新手机号,绑定登入成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setMobile(null);
			int uid = JUserCallService.createUserCall(cur);
			String aliUserId = "ali_"+TestDataManager.getRandomNum(10);
			BindThirdPartyUserReq third=JUserCallService.initBindThirdUserReq(uid);
			third.setThirdPartyId(aliUserId);
			third.setThirdPartyType(ThirdPartyTypeEnum.Alipay);
			JUserCallService.bindThirdPartyUserCall(third);
			
			loginBean=JUserCallService.initLoginBean();
			loginBean.setThirdPartyType(ThirdPartyTypeEnum.Alipay);
			loginBean.setMobile(TestDataManager.getPhoneNum());
			loginBean.setThirdPartyId(aliUserId);
		
			loginCall.setData(loginBean);
			loginCall.callService();			
			
			Logger.verifyIsContains("登录成功", loginCall.getString("SuccessMessage"), "验证返回的SuccessMessage信息");
			Logger.verifyEquals("200" ,loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", loginCall.getString("Success"), "验证是否成功");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
//	8.三方联合登入时传入已存在未解绑第三方账号,码头用户手机为空,第三方传入手机号是已存在码头用户,失败
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ThirdpartyLogin_008() {
		Logger.start(true,"三方联合登入时传入已存在未解绑第三方账号,码头用户手机为空,第三方传入手机号是已存在码头用户,失败");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setMobile(null);
			int uid = JUserCallService.createUserCall(cur);
			String aliUserId = "ali_"+TestDataManager.getRandomNum(10);
			BindThirdPartyUserReq third=JUserCallService.initBindThirdUserReq(uid);
			third.setThirdPartyId(aliUserId);
			third.setThirdPartyType(ThirdPartyTypeEnum.Alipay);
			JUserCallService.bindThirdPartyUserCall(third);
			
			CreateUserReq cur2 = new CreateUserReq();
			cur2 = JUserCallService.initCreateUserBean(cur2);
			 JUserCallService.createUserCall(cur2);
			 
			 loginBean=JUserCallService.initLoginBean();
			loginBean.setMobile(cur2.getMobile());
			loginBean.setThirdPartyId(aliUserId);
			loginBean.setThirdPartyType(ThirdPartyTypeEnum.Alipay);
			loginCall.setData(loginBean);
			loginCall.callService();			
			
			Logger.verifyIsContains("该手机号码已经绑定过码头账号了，换一个试试吧~", loginCall.getString("LastErrorMessage"), "验证返回的LastErrorMessage信息");
			Logger.verifyEquals("400" ,loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("false", loginCall.getString("Success"), "验证是否成功");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
//	9.三方联合登入时传入已存在已解绑第三方账号,第三方手机号是新手机,注册登入成功
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ThirdpartyLogin_009() {
		Logger.start(true,"三方联合登入时传入已存在已解绑第三方账号,第三方手机号是新手机,注册登入成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			String aliUserId = "ali_"+TestDataManager.getRandomNum(10);
			BindThirdPartyUserReq third=JUserCallService.initBindThirdUserReq(uid);
			third.setThirdPartyType(ThirdPartyTypeEnum.Alipay);
			JUserCallService.bindThirdPartyUserCall(third);
			UnBindThirdPartyUserReq ubtrd=new UnBindThirdPartyUserReq();
			ubtrd.setThirdPartyId(third.getThirdPartyId());
			ubtrd.setUserId(uid);
			ubtrd.setThirdPartyType(ThirdPartyTypeEnum.Alipay);
			JUserCallService.UnBindThirdPartyUserCall(ubtrd);
			
			loginBean=JUserCallService.initLoginBean();
			
			loginBean.setMobile(TestDataManager.getPhoneNum());
			loginBean.setThirdPartyId(aliUserId);
			
			loginCall.setData(loginBean);
			loginCall.callService();
			
			int nuid=loginCall.getJsonObject().get("Result").getAsJsonObject().get("UserId").getAsInt();
			Logger.verifyEquals("new", loginCall.getResult().get("Remark"), "验证Remark信息");
			Logger.verifyEquals(ECode.SUCCESS, loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", loginCall.getString("Success"), "验证是否成功");
			
			verifyDBBind(nuid,loginBean);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
//	10.三方联合登入时传入已存在已解绑第三方账号,第三方手机号是码头已存在未绑定第三方手机号,绑定成功
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ThirdpartyLogin_010() {
		//绑定解绑再绑定
		Logger.start(true,"三方联合登入时传入已存在已解绑第三方账号,第三方手机号是码头已存在未绑定第三方手机号,绑定成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			String aliUserId = "ali_"+TestDataManager.getRandomNum(10);
			BindThirdPartyUserReq third=JUserCallService.initBindThirdUserReq(uid);
			third.setThirdPartyType(ThirdPartyTypeEnum.Alipay);
			JUserCallService.bindThirdPartyUserCall(third);
			UnBindThirdPartyUserReq ubtrd=new UnBindThirdPartyUserReq();
			ubtrd.setThirdPartyId(third.getThirdPartyId());
			ubtrd.setUserId(uid);
			ubtrd.setThirdPartyType(ThirdPartyTypeEnum.Alipay);
			JUserCallService.UnBindThirdPartyUserCall(ubtrd);
			
			loginBean=JUserCallService.initLoginBean();
			
			loginBean.setMobile(cur.getMobile());
			loginBean.setThirdPartyId(aliUserId);

			loginCall.setData(loginBean);
			loginCall.callService();	
			
			Logger.verifyEquals("登录成功", loginCall.getString("SuccessMessage"), "验证返回的Message信息");
			Logger.verifyEquals(ECode.SUCCESS, loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", loginCall.getString("Success"), "验证是否成功");
			
			verifyDBBind(uid,loginBean);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
//	11.三方联合登入时传入已存在已解绑第三方账号,第三方手机号是码头已存在已绑定第三方手机号,失败
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ThirdpartyLogin_011() {
		Logger.start(true,"三方联合登入时传入已存在已解绑第三方账号,第三方手机号是码头已存在已绑定第三方手机号,失败");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			String aliUserId = "ali_"+TestDataManager.getRandomNum(10);
			BindThirdPartyUserReq third=JUserCallService.initBindThirdUserReq(uid);
			third.setThirdPartyType(ThirdPartyTypeEnum.QQ);
			JUserCallService.bindThirdPartyUserCall(third);
			UnBindThirdPartyUserReq ubtrd=new UnBindThirdPartyUserReq();
			ubtrd.setThirdPartyId(third.getThirdPartyId());
			ubtrd.setUserId(uid);
			ubtrd.setThirdPartyType(ThirdPartyTypeEnum.QQ);
			JUserCallService.UnBindThirdPartyUserCall(ubtrd);
			
			CreateUserReq cur2 = new CreateUserReq();
			cur2 = JUserCallService.initCreateUserBean(cur2);
			int uid2= JUserCallService.createUserCall(cur2);
			BindThirdPartyUserReq third2=JUserCallService.initBindThirdUserReq(uid2);
			third2.setThirdPartyType(ThirdPartyTypeEnum.QQ);
			JUserCallService.bindThirdPartyUserCall(third2);
			
			loginBean=JUserCallService.initLoginBean();
			
			loginBean.setMobile(cur2.getMobile());
			loginBean.setThirdPartyId(aliUserId);

			loginCall.setData(loginBean);
			loginCall.callService();	
			
			Logger.verifyIsContains("该手机号码已经绑定过QQ了，换一个试试吧~", loginCall.getString("LastErrorMessage"), "验证返回的LastErrorMessage信息");
			Logger.verifyEquals("400", loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("false", loginCall.getString("Success"), "验证是否成功");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
//	12.三方联合登入时传入已存在未解绑第三方账号,码头用户手机不为空第三方手机号为空,登入成功	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ThirdpartyLogin_012() {
		Logger.start(true,"三方联合登入时传入已存在未解绑第三方账号,码头用户手机不为空第三方手机号为空,登入成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			String aliUserId = "ali_"+TestDataManager.getRandomNum(10);
			BindThirdPartyUserReq third=JUserCallService.initBindThirdUserReq(uid);
			third.setThirdPartyType(ThirdPartyTypeEnum.Alipay);
			third.setThirdPartyId(aliUserId);
			JUserCallService.bindThirdPartyUserCall(third);
			
			loginBean=JUserCallService.initLoginBean();
			loginBean.setThirdPartyType(ThirdPartyTypeEnum.Alipay);
			loginBean.setThirdPartyId(aliUserId);

			loginCall.setData(loginBean);
			loginCall.callService();			
			
			Logger.verifyEquals("login", loginCall.getResult().get("Remark"), "验证Remark信息");
			Logger.verifyEquals("200" ,loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", loginCall.getString("Success"), "验证是否成功");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ThirdpartyLogin_013() {
		Logger.start(false,"不输入Ali用户Id，用户创建失败");
		try {
			loginBean=JUserCallService.initLoginBean();
			loginBean.setThirdPartyId(null);
			
			loginCall.setData(loginBean);
			loginCall.callService();
			
			Logger.verifyEquals("false", loginCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals(ECode.ERROR400, loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyIsContains("错误的请求参数|无效的第三方用户Id", loginCall.getString("LastErrorMessage"), "验证返回的Message信息");
			Logger.verifyEquals("IllegalArgument", loginCall.getResult().get("VerifyCode"), "验证凭据");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ThirdpartyLogin_014(){
		Logger.start(true,"不输入真实用户名，用户创建成功");
		try {
			loginBean=JUserCallService.initLoginBean();
			
			loginBean.setThirdPartyUserName(null);
			String phone = TestDataManager.getPhoneNum();			
			loginBean.setMobile(phone);
			
			loginCall.setData(loginBean);
			loginCall.callService();	
			
			int nuid=loginCall.getJsonObject().get("Result").getAsJsonObject().get("UserId").getAsInt();
			Logger.verifyEquals("注册成功", loginCall.getString("SuccessMessage"), "验证返回的Message信息");
			Logger.verifyEquals(ECode.SUCCESS, loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", loginCall.getString("Success"), "验证是否成功");
			
			Logger.verifyEquals("new", loginCall.getResult().get("Remark"), "验证Remark信息");
			Logger.verifyEquals("Success", loginCall.getResult().get("VerifyCode"), "验证凭据");
		
			verifyDB(nuid,loginBean);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ThirdpartyLogin_015(){
		Logger.start(false,"不输入手机，用户创建失败");
		try {
			loginBean=JUserCallService.initLoginBean();
			
			loginCall.setData(loginBean);
			loginCall.callService();	
			
			Logger.verifyEquals("为了您的账户安全，请绑定你的手机号码", loginCall.getString("LastErrorMessage"), "验证返回的Message信息");
			Logger.verifyEquals(ECode.ERROR400, loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("false", loginCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals("NeedBindMobile", loginCall.getResult().get("VerifyCode"), "验证凭证");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ThirdpartyLogin_016() {
		Logger.start(true,"QQ账号第一次授权,创建用户成功,用户名长度大于20");
		try {
			loginBean=JUserCallService.initLoginBean();
			
			String phone = TestDataManager.getPhoneNum();
			
			Logger.comment("绑定手机号，注册QQ账号");
			loginBean.setThirdPartyUserName("regAliUser_"+TestDataManager.getRandomNum(20));	
			loginBean.setMobile(phone);
			
			loginCall.setData(loginBean);
			loginCall.callService();			
			Logger.verifyEquals("new", loginCall.getResult().get("Remark"), "验证Remark信息");
			Logger.verifyEquals(ECode.SUCCESS, loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", loginCall.getString("Success"), "验证是否成功");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ThirdpartyLogin_017() {
		Logger.start(false,"QQ账号第一次授权,创建用户失败,用户名长度大于100");
		try {
			String aliUserId = "ali_"+TestDataManager.getRandomNum(181);
			
			String phone = TestDataManager.getPhoneNum();
			
			Logger.comment("绑定手机号，注册QQ账号");
			loginBean=JUserCallService.initLoginBean();
			loginBean.setThirdPartyId(aliUserId);
			loginBean.setMobile(phone);

			loginCall.setData(loginBean);
			loginCall.callService();			
			String VerifyCode=loginCall.getJsonObject().get("Result").getAsJsonObject().get("VerifyCode").getAsString();
			Logger.verifyEquals("IllegalArgument", VerifyCode, "验证返回的LoginNameLengthError信息");
			Logger.verifyEquals("400", loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("false", loginCall.getString("Success"), "验证是否成功");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ThirdpartyLogin_018() {
		Logger.start(true,"传入TokenSource为sellerapp用户注册成功JIRACONN-2123");
		try {
			String phone = TestDataManager.getPhoneNum();
			
			Logger.comment("绑定手机号，注册QQ账号");
			
			loginBean=JUserCallService.initLoginBean();
			loginBean.setMobile(phone);
			loginBean.setTokenSource("sellerapp");
			
			loginCall.setData(loginBean);
			loginCall.callService();			
			Logger.verifyEquals("注册成功", loginCall.getString("SuccessMessage"), "验证返回的Message信息");
			Logger.verifyEquals(ECode.SUCCESS, loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", loginCall.getString("Success"), "验证是否成功");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ThirdpartyLogin_019() {
		Logger.start(true,"传入TokenSource为app用户注册成功JIRACONN-2123");
		try {
			String aliUserId = "ali_"+TestDataManager.getRandomNum(10);
			
			String phone = TestDataManager.getPhoneNum();
			
			Logger.comment("绑定手机号，注册QQ账号");

			loginBean=JUserCallService.initLoginBean();
			
			loginBean.setMobile(phone);
			loginBean.setTokenSource("app");
			loginCall.setData(loginBean);
			loginCall.callService();		
			
			Logger.verifyEquals("注册成功", loginCall.getString("SuccessMessage"), "验证返回的Message信息");
			Logger.verifyEquals(ECode.SUCCESS, loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", loginCall.getString("Success"), "验证是否成功");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ThirdpartyLogin_020() {
		Logger.start(false,"特殊字符用户名失败JIRACONN-2522");
		try {
			
			String phone = TestDataManager.getPhoneNum();
			
			Logger.comment("绑定手机号，注册QQ账号");

			loginBean=JUserCallService.initLoginBean();
			
			loginBean.setThirdPartyUserName("#$%%%");
			loginBean.setMobile(phone);
			
			loginCall.setData(loginBean);
			loginCall.callService();			
			String VerifyCode=loginCall.getJsonObject().get("Result").getAsJsonObject().get("VerifyCode").getAsString();
			Logger.verifyEquals("LoginNameContainSQLSensitiveCode", VerifyCode, "验证返回的LoginNameContextError信息");
			Logger.verifyEquals(ECode.ERROR400, loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("false", loginCall.getString("Success"), "验证是否成功");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ThirdpartyLogin_021() {
		Logger.start(true,"第三方账号已存在，App");
		try {
			String aliUserId = "ali_"+TestDataManager.getRandomNum(10);
			String phone = TestDataManager.getPhoneNum();  
			
			Logger.comment("绑定手机号，注册QQ账号");

			loginBean=JUserCallService.initLoginBean();
			
			loginBean.setMobile(phone);

			loginCall.setData(loginBean);
			loginCall.callService();	
			Logger.verifyEquals(ECode.SUCCESS, loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", loginCall.getString("Success"), "验证是否成功");
			
			loginBean.setAppSource(AppSourceEnum.Wap);
			loginCall.setData(loginBean);
			loginCall.callService();	
			
			Logger.verifyEquals(ECode.SUCCESS, loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", loginCall.getString("Success"), "验证是否成功");
			Integer uid=loginCall.getJsonObject().get("Result").getAsJsonObject().get("UserId").getAsInt();
			Logger.comment("和数据库进行数据校验");

			loginBean.setAppSource(AppSourceEnum.App);
			verifyDB(uid,loginBean);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ThirdpartyLogin_022() {
		Logger.start(false,"QQ账号第一次授权,thirdPartyUserName纯数字报错");
		try {
			String aliUserId = TestDataManager.getRandomNum(10);
			
			String phone = TestDataManager.getPhoneNum();
			
			Logger.comment("绑定手机号，注册QQ账号");
			loginBean=JUserCallService.initLoginBean();
			loginBean.setThirdPartyUserName(aliUserId);
			loginBean.setMobile(phone);

			loginCall.setData(loginBean);
			loginCall.callService();	
			
			String VerifyCode=loginCall.getJsonObject().get("Result").getAsJsonObject().get("VerifyCode").getAsString();
			Logger.verifyEquals("LoginNameFullNumberError", VerifyCode, "验证返回的LoginNameLengthError信息");
			Logger.verifyEquals("400", loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("false", loginCall.getString("Success"), "验证返回Success");
			Logger.verifyEquals("登录昵称不能全数字错误", loginCall.getString("LastErrorMessage"), "验证返回LastErrorMessage");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ThirdpartyLogin_023() {
		Logger.start(false,"QQ账号第一次授权,thirdPartyUserName特殊字符");
		try {
			String aliUserId = "@###+"+TestDataManager.getRandomNum(10);
			
			String phone = TestDataManager.getPhoneNum();
			
			Logger.comment("绑定手机号，注册QQ账号");
			loginBean=JUserCallService.initLoginBean();
			loginBean.setThirdPartyUserName(aliUserId);
			loginBean.setMobile(phone);

			loginCall.setData(loginBean);
			loginCall.callService();	
			
			String VerifyCode=loginCall.getJsonObject().get("Result").getAsJsonObject().get("VerifyCode").getAsString();
			Logger.verifyEquals("LoginNameContainSQLSensitiveCode", VerifyCode, "验证返回的LoginNameLengthError信息");
			Logger.verifyEquals("400", loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("false", loginCall.getString("Success"), "验证返回Success");
			Logger.verifyIsContains("敏感字符", loginCall.getString("LastErrorMessage"), "验证返回LastErrorMessage");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ThirdpartyLogin_024() {
		Logger.start(false,"QQ账号第一次授权,thirdPartyUserName_开头");
		try {
			String aliUserId = "_"+TestDataManager.getRandomNum(10);
			
			String phone = TestDataManager.getPhoneNum();
			
			Logger.comment("绑定手机号，注册QQ账号");
			loginBean=JUserCallService.initLoginBean();
			loginBean.setThirdPartyUserName(aliUserId);
			loginBean.setMobile(phone);

			loginCall.setData(loginBean);
			loginCall.callService();	
			
			String VerifyCode=loginCall.getJsonObject().get("Result").getAsJsonObject().get("VerifyCode").getAsString();
			Logger.verifyEquals("LoginNameFistLastError", VerifyCode, "验证返回的LoginNameLengthError信息");
			Logger.verifyEquals("400", loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("false", loginCall.getString("Success"), "验证返回Success");
			Logger.verifyEquals("登录名称（昵称）首末位错误（昵称首位和末位不能是下划线'_'）", loginCall.getString("LastErrorMessage"), "验证返回LastErrorMessage");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ThirdpartyLogin_025() {
		Logger.start(true,"QQ账号第一次授权,创建用户成功_含中文");
		try {
			String aliUserId = "八哥天才_"+TestDataManager.getRandomNum(10);
			String phone = TestDataManager.getPhoneNum();
			
			Logger.comment("绑定手机号，注册QQ账号");
			loginBean=JUserCallService.initLoginBean();
			loginBean.setThirdPartyUserName(aliUserId);
			loginBean.setMobile(phone);
			
			loginCall.setData(loginBean);
			loginCall.callService();	
			
			Logger.verifyEquals(ECode.SUCCESS, loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", loginCall.getString("Success"), "验证是否成功");
			Integer uid=loginCall.getJsonObject().get("Result").getAsJsonObject().get("UserId").getAsInt();
		
			Logger.comment("和数据库进行数据校验");
			verifyDB(uid,loginBean);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ThirdpartyLogin_026() {
		Logger.start(true,"WxApp账号第一次授权,创建用户成功");
		try {
			String wapp = "wxapp_"+TestDataManager.getRandomNum(10);
			String phone = TestDataManager.getPhoneNum();
			
			loginBean=JUserCallService.initLoginBean();
			loginBean.setThirdPartyId(wapp);
			loginBean.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
			loginBean.setAppSource(AppSourceEnum.WxApp);
			loginBean.setMobile(phone);
			loginBean.setDid("testChannelSource");
			loginBean.setOpenId(TestDataManager.getRandomUUID().toString().replaceAll("-", ""));
			loginCall.setData(loginBean);
			loginCall.callService();	
			
			Logger.verifyEquals(ECode.SUCCESS, loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", loginCall.getString("Success"), "验证是否成功");
			Integer uid=loginCall.getJsonObject().get("Result").getAsJsonObject().get("UserId").getAsInt();
		
			Logger.comment("和数据库进行数据校验");
			verifyDB(uid,loginBean);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ThirdpartyLogin_027() {
		Logger.start(true,"用户手机注册过WxApp账号授权,登入用户成功");
		try {
			String wapp = "wxapp_"+TestDataManager.getRandomNum(10);
			String phone = TestDataManager.getPhoneNum();
			Logger.comment(phone+":用户注册");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			regbean.setLoginMobile(phone);
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			Integer uid=urrc.getUserid();
			
			loginBean=JUserCallService.initLoginBean();
			loginBean.setThirdPartyId(wapp);
			loginBean.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
			loginBean.setAppSource(AppSourceEnum.WxApp);
			loginBean.setMobile(phone);
			loginBean.setDid("gotologin");
			loginBean.setOpenId(TestDataManager.getRandomUUID().toString().replaceAll("-", ""));
			loginCall.setData(loginBean);
			loginCall.callService();	
			
			Logger.verifyEquals(ECode.SUCCESS, loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", loginCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals("登录成功", loginCall.getString("SuccessMessage"), "验证SuccessMessage");
//			Integer uid=loginCall.getJsonObject().get("Result").getAsJsonObject().get("UserId").getAsInt();
		
			Logger.comment("和数据库进行数据校验");
			verifyDB(uid,loginBean);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ThirdpartyLogin_028() {
		Logger.start(true,"用户WxWap注册过WxApp账号授权,不输入手机号登入用户成功");
		try {
			String wapp = "wxapp_"+TestDataManager.getRandomNum(10);
			String phone = TestDataManager.getPhoneNum();
			Logger.comment(phone+":用户WX注册");
			WeiXinUserRequestDtoBean wx = JUserCallService.initWeiXinUserRequestDtoBeanForRegister();
			wx.setMobile(phone);
			WeiXinUserRequestDtoCall urrc = JUserCallService.weiXinUserRequestDto(wx);
			Integer uid=urrc.getUid();
			
			loginBean=JUserCallService.initLoginBean();
			loginBean.setThirdPartyId(wx.getUnionId());
			loginBean.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
			loginBean.setAppSource(AppSourceEnum.WxApp);
//			loginBean.setMobile(phone);
			loginBean.setDid("gotologin");
			loginBean.setOpenId(TestDataManager.getRandomUUID().toString().replaceAll("-", ""));
			loginCall.setData(loginBean);
			loginCall.callService();	
			
			Logger.verifyEquals(ECode.SUCCESS, loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", loginCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals("登录成功", loginCall.getString("SuccessMessage"), "验证SuccessMessage");
//			Integer uid=loginCall.getJsonObject().get("Result").getAsJsonObject().get("UserId").getAsInt();
		
			Logger.comment("和数据库进行数据校验");
			verifyDB(uid,loginBean);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ThirdpartyLogin_029() {
		Logger.start(true,"用户WxWap注册过WxApp账号授权,输入正确手机号登入用户成功");
		try {
			String wapp = "wxapp_"+TestDataManager.getRandomNum(10);
			String phone = TestDataManager.getPhoneNum();
			Logger.comment(phone+":用户WX注册");
			WeiXinUserRequestDtoBean wx = JUserCallService.initWeiXinUserRequestDtoBeanForRegister();
			wx.setMobile(phone);
			WeiXinUserRequestDtoCall urrc = JUserCallService.weiXinUserRequestDto(wx);
			Integer uid=urrc.getUid();
			
			loginBean=JUserCallService.initLoginBean();
			loginBean.setThirdPartyId(wx.getUnionId());
			loginBean.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
			loginBean.setAppSource(AppSourceEnum.WxApp);
			loginBean.setMobile(phone);
			loginBean.setDid("gotologin");
			loginBean.setOpenId(TestDataManager.getRandomUUID().toString().replaceAll("-", ""));
			loginCall.setData(loginBean);
			loginCall.callService();	
			
			Logger.verifyEquals(ECode.SUCCESS, loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", loginCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals("登录成功", loginCall.getString("SuccessMessage"), "验证SuccessMessage");
//			Integer uid=loginCall.getJsonObject().get("Result").getAsJsonObject().get("UserId").getAsInt();
		
			Logger.comment("和数据库进行数据校验");
			verifyDB(uid,loginBean);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ThirdpartyLogin_030() {
		Logger.start(true,"用户WxWap注册过WxApp账号授权,输入错误手机号登入用户失败");
		try {
			String wapp = "wxapp_"+TestDataManager.getRandomNum(10);
			String phone = TestDataManager.getPhoneNum();
			Logger.comment(phone+":用户WX注册");
			WeiXinUserRequestDtoBean wx = JUserCallService.initWeiXinUserRequestDtoBeanForRegister();
			wx.setMobile(phone);
			WeiXinUserRequestDtoCall urrc = JUserCallService.weiXinUserRequestDto(wx);
			Integer uid=urrc.getUid();
			
			loginBean=JUserCallService.initLoginBean();
			loginBean.setThirdPartyId(wx.getUnionId());
			loginBean.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
			loginBean.setAppSource(AppSourceEnum.WxApp);
			loginBean.setMobile(phone+1);
			loginBean.setDid("gotologin");
			loginBean.setOpenId(TestDataManager.getRandomUUID().toString().replaceAll("-", ""));
			loginCall.setData(loginBean);
			loginCall.callService();	
			
			Logger.verifyEquals(ECode.ERROR400, loginCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("false", loginCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals("当前账号已绑定", loginCall.getString("LastErrorMessage"), "验证LastErrorMessage");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}